package model;

import java.io.Serializable;

import javafx.beans.property.BooleanProperty;
import javafx.beans.property.SimpleBooleanProperty;

public class ListItem implements Comparable<ListItem>, Serializable
{
	private String name;
	private transient BooleanProperty selected;
	private boolean selectedPrimitive;
	
	public ListItem(String name)
	{
		this.name = name;
		selectedPrimitive = false;
	}
	
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public boolean isSelected() 
	{
		if (selected==null)
			selected = new SimpleBooleanProperty(selectedPrimitive);
		
		return selected.getValue();
	}
	
	public void setSelected(boolean v) 
	{
		this.selectedPrimitive = v;
		this.selected = new SimpleBooleanProperty(v);
	}
	
	public BooleanProperty getIsSelected()
	{
		if (selected==null)
			selected = new SimpleBooleanProperty(selectedPrimitive);
		
		return selected;
	}
	
	@Override
	public boolean equals(Object obj) 
	{
		if (!(obj instanceof ListItem))
			return false;
		
		ListItem l = (ListItem) obj;
		
		return this.getName().equals(l.getName());
	}
	
	@Override
	public String toString() {
		if (isSelected())
			return getName();
		else
			return "!" + getName();
	}

	@Override
	public int compareTo(ListItem o) 
	{
		return getName().compareTo(o.getName());
	}
}
